import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Global } from "../../../../com/gengine/global/Global";
import { WindowLayer } from "../../manager/WindowLayer";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { EquipmentStrengthAddPanel } from "../player/equip/EquipmentStrengthAddPanel";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { EquipmentJewelAddPanel } from "../player/equip/EquipmentJewelAddPanel";
import { EquipsPanel } from "../player/equip/EquipsPanel";
import { GuildVipItem } from "../guild/GuildVipItem";
import { GTextFormat } from "../../../common/GTextFormat";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ResFileConst } from "../../resource/ResFileConst";
import { FontUtil } from "../../../common/font/FontUtil";
import { AvatarUploadPanel } from "../player/AvatarUploadPanel";
import { PlayerRuneFightBtn } from "../player/equip/PlayerRuneFightBtn";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SVotePlayer } from "../../../../Message/Game/SVotePlayer";
import { MsgManager } from "../../manager/MsgManager";
import { Cache } from "../../cache/Cache";
import { SLookupPlayerReply } from "../../../../Message/Game/SLookupPlayerReply";
import { UserEquipmentUtil } from "./userEquip/UserEquipmentUtil";
import { ColorConfig } from "../../resource/ColorConfig";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { CareerConfig } from "../../resource/CareerConfig";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { StatueUserPlayer } from "../../scene/player/entity/StatueUserPlayer";
import { DirectionType } from "../../scene/modle/data/DirectionType";
import { TToplist } from "../../../../Message/Db/Tables/TToplist";
import { _type } from "../../../../this/_type";
import { _playerId } from "../../../../this/_playerId";
type int = number;
//class PlayerEquipPanel
    
    export  class PlayerEquipPanel extends View
    {
        constructor(arg1: Boolean=true)
        {
            super();
            this._stagerect = new Object /* flash.geom.Rectangle */();
            _layer = LayerManager.windowLayer;
            this.init();
            if (arg1) 
            {
                addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStageHandler);
            }
            return;
        }

        public get closeBtn(): GButton
        {
            return this._closeBtn;
        }

        public disposeModel(): void
        {
            if (this._userModel) 
            {
                this._userModel.dispose(false);
            }
            return;
        }

        /* internal  */onAddToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMouseDownHandler);
            addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            return;
        }

        /* internal  */onRemoveFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            this.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMouseDownHandler);
            removeEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            return;
        }

        /* internal  */onMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            if (typeof _layer === "windowlayer") 
            {
                this._stagerect.x = 0;
                this._stagerect.y = 0;
                this._stagerect.width = this.stage.stageWidth;
                this._stagerect.height = this.stage.stageHeight;
                this.startDrag(false, this._stagerect);
            }
            else 
            {
                this.startDrag(false);
            }
            return;
        }

        /* internal  */onMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            this.stopDrag();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ObjCreate.createBg(0, 0, 260, 495, this, ImagesConst.WindowCenterA);
            var loc2=ObjCreate.createBg(5, 5, 250, 485, this, ImagesConst.WindowCenterB);
            var loc3=new Object /* flash.display.Bitmap */();
            loc3.x = 60;
            loc3.y = 95;
            addChild(loc3);
            LoaderHelp.setBitmapdata("RangeBg.swf", loc3);
            this._closeBtn = ObjCreate.createGButton("", 232, 5, 19, 19, this, "CloseButton");
            this._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCloseBtnClickHandler);
            this._closeBtn.visible = false;
            this._strengthAddPanel = new EquipmentStrengthAddPanel();
            this._strengthAddPanel.x = 70;
            this._strengthAddPanel.y = 105;
            this._strengthAddPanel.visible = false;
            addChild(this._strengthAddPanel);
            this._strengthAddPanel.mode = GModuleEvent.Mode_Other;
            this._jewelAddPanel = new EquipmentJewelAddPanel();
            this._jewelAddPanel.x = 155;
            this._jewelAddPanel.y = 105;
            this._jewelAddPanel.visible = false;
            addChild(this._jewelAddPanel);
            this._jewelAddPanel.mode = GModuleEvent.Mode_Other;
            this._equipsPanel = new EquipsPanel();
            this._equipsPanel.x = 5;
            this._equipsPanel.y = 65;
            this._equipsPanel.mode = GModuleEvent.Mode_Other;
            this._equipsPanel.setAddPanelVisible(false);
            this._equipsPanel.changeNormalBtn();
            addChild(this._equipsPanel);
            this._vipItem = new GuildVipItem();
            this._vipItem.x = 15;
            this._vipItem.y = 63;
            addChild(this._vipItem);
            this._adoreTf = new GTextFormat("", 12, 16765990);
            this._despiseTf = new GTextFormat("", 12, 7203361);
            this._notOnlineTf = new GTextFormat("", 12, 16776960);
            this._nameTf = new GTextFormat("", 13, 15788607);
            this._campTxt = this.createTextfield(80, 30, 30, 25, "");
            this._nameTxt = this.createTextfield(110, 30, 100, 25, "", this._nameTf);
            this._level = this.createTextfield(70, 60, 40, 20, "", GlobalStyle.textFormat2);
            this._career = this.createTextfield(140, 60, 40, 20, "", GlobalStyle.textFormat2);
            this._levelTxt = this.createTextfield(105, 60, 40, 20, "", GlobalStyle.textFormat1);
            this._careerTxt = this.createTextfield(175, 60, 40, 20, "", GlobalStyle.textFormat1);
            this._notOnline = ObjCreate.createTextField(Language.getString(30005), 103, 180, 80, 20, this, this._notOnlineTf);
            var loc4=this.createTextfield(50, 400, 100, 20, Language.getString(32107) + "：", this._adoreTf);
            var loc5=this.createTextfield(50, 420, 100, 20, Language.getString(32108) + "：", this._despiseTf);
            this._adoreNum = this.createTextfield(120, 400, 100, 20, "0", this._adoreTf);
            this._despiseNum = this.createTextfield(120, 420, 100, 20, "0", this._despiseTf);
            var loc6;
            (loc6 = GlobalClass.getBitmap(ImagesConst.RangeAdore)).x = 180;
            loc6.y = 400;
            addChild(loc6);
            var loc7;
            (loc7 = GlobalClass.getBitmap(ImagesConst.RangeDespise)).x = 180;
            loc7.y = 420;
            addChild(loc7);
            var loc8=new GTextFormat(null, 12, 16121600);
            this._adoreBtn = new GButton();
            this._adoreBtn.move(45, 445);
            this._adoreBtn.setSize(77, 22);
            this._adoreBtn.label = Language.getString(32058);
            this._adoreBtn.styleName = "ButtonYellow";
            this._adoreBtn.enabled = false;
            this._adoreBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAdoreBtnClickHandler);
            addChild(this._adoreBtn);
            this._despiseBtn = new GButton();
            this._despiseBtn.move(140, 445);
            this._despiseBtn.setSize(77, 22);
            this._despiseBtn.label = Language.getString(32059);
            this._despiseBtn.styleName = "ButtonYellow";
            this._despiseBtn.enabled = false;
            this._despiseBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onDespiseBtnClickHandler);
            addChild(this._despiseBtn);
            this._restVoteTxt = this.createTextfield(50, 470, 200, 20, "", GlobalStyle.textFormat5);
            ObjCreate.createBg(67, 370, 135, 24, this, ImagesConst.SelectedBg);
            ObjCreate.createGLoadedButton(ResFileConst.FightingIcon, 77, 373, 19, 18, this);
            this._fightStrengthTxt = ObjCreate.createTextField("--", 107, 372, 60, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._fightStrengthTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._avatarUpload = new AvatarUploadPanel();
            this._avatarUpload.x = 15;
            this._avatarUpload.y = 15;
            addChild(this._avatarUpload);
            this._avatarUpload.mode = GModuleEvent.Mode_Other;
            this._avatarUpload.visible = false;
            this._runeFight = new PlayerRuneFightBtn();
            this._runeFight.x = 175;
            this._runeFight.y = 20;
            this._runeFight.setRuneLookup(false);
            addChild(this._runeFight);
            this._runeFight.visible = false;
            return;
        }

        /* internal  */onCloseBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */createTextfield(arg1: int, arg2: int, arg3: int, arg4: int, arg5: string, arg6: Object /* flash.text.TextFormat */=null): Object /* flash.text.TextField */
        {
            var loc1;
            (loc1 = new Object /* flash.text.TextField */()).x = arg1;
            loc1.y = arg2;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.text = arg5;
            loc1.selectable = false;
            if (arg6 != null) 
            {
                loc1.setTextFormat(arg6);
            }
            addChild(loc1);
            return loc1;
        }

        /* internal  */onAdoreBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._type = this.Vote_Adore_Type;
            Dispatcher.dispatchEvent(new DataEvent(EventName.VotePlayer, {"type": _type, "playerId": _playerId}));
            return;
        }

        /* internal  */onDespiseBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._type = this.Vote_Despise_Type;
            Dispatcher.dispatchEvent(new DataEvent(EventName.VotePlayer, {"type": _type, "playerId": _playerId}));
            return;
        }

        public voteSuccess(arg1: SVotePlayer): void
        {
            if (arg1.type != this.Vote_Adore_Type) 
            {
                if (arg1.type == this.Vote_Despise_Type) 
                {
                    this._despise = this._despise + 1;
                    this._despiseNum.text = this._despise.toString();
                    this._despiseNum.setTextFormat(this._despiseTf);
                    MsgManager.showRollTipsMsg(Language.getString(32061));
                }
            }
            else 
            {
                this._adore = this._adore + 1;
                this._adoreNum.text = this._adore.toString();
                this._adoreNum.setTextFormat(this._adoreTf);
                MsgManager.showRollTipsMsg(Language.getString(32060));
            }
            --Cache.instance.ranking.voteCount;
            this.showVote();
            return;
        }

        public setData(arg1: Object, arg2: SLookupPlayerReply): void
        {
            if (this._userModel) 
            {
                this._userModel.dispose(false);
            }
            var loc1=arg2.miniPlayer;
            this._playerId = arg2.miniPlayer.entityId.id;
            this._adore = arg1.adoreNum;
            this._despise = arg1.despiseNum;
            this._adoreNum.text = this._adore.toString();
            this._adoreNum.setTextFormat(this._adoreTf);
            this._despiseNum.text = this._despise.toString();
            this._despiseNum.setTextFormat(this._despiseTf);
            var loc2=arg1.equipArr;
            var loc3=UserEquipmentUtil.getUserEquipmentData(loc2, arg2.fashionState, arg2.wingState, arg2.fashionWeaponState, arg2.surroundState, arg2.waistBeltState, true);
            this._equipsPanel.setEquipments(loc2);
            this._equipsPanel.updateFashionJewelInfo(arg2.fashionJewelInfo, loc1.level);
            this._equipsPanel.curLv = loc1.level;
            this._equipsPanel.curCareer = loc1.career;
            this._equipsPanel.flyLv = arg2.flyLevel;
            this._notOnline.text = "";
            if (this._playerId == Cache.instance.role.entityInfo.entityId.id) 
            {
                this._adoreBtn.enabled = false;
                this._despiseBtn.enabled = false;
            }
            else 
            {
                this._adoreBtn.enabled = true;
                this._despiseBtn.enabled = true;
            }
            var loc4=ColorConfig.instance.getCountryColor(loc1.camp).intColor;
            var loc5=GameDefConfig.instance.getECamp(loc1.camp);
            this._nameTxt.text = ". " + loc1.name;
            this._nameTxt.setTextFormat(this._nameTf);
            this._campTxt.text = loc5;
            this._campTxt.setTextFormat(new GTextFormat("", 13, loc4));
            this._levelTxt.text = loc1.level.toString();
            this._levelTxt.setTextFormat(GlobalStyle.textFormat1);
            this._careerTxt.text = CareerConfig.instance.getInfoByCode(loc1.career).name;
            this._careerTxt.setTextFormat(GlobalStyle.textFormat1);
            this._level.text = Language.getString(30008);
            this._level.setTextFormat(GlobalStyle.textFormat2);
            this._career.text = Language.getString(30006);
            this._career.setTextFormat(GlobalStyle.textFormat2);
            this._fightStrengthTxt.text = arg2.fight + "";
            this.addUserModel(loc3.equipDic, loc1, loc3.weaponStPerLv, loc3.wingStLv);
            this._strengthAddPanel.curCareer = loc1.career;
            this._strengthAddPanel.updateAddInfo();
            this._strengthAddPanel.visible = true;
            this._jewelAddPanel.curCareer = loc1.career;
            this._jewelAddPanel.updateAddInfo();
            this._jewelAddPanel.visible = true;
            this._vipItem.vip = loc1.VIP;
            this._avatarUpload.visible = true;
            this._avatarUpload.sex = arg2.miniPlayer.sex;
            this._avatarUpload.updateUploadAvatar(arg2.miniPlayer.photo, arg2.miniPlayer.entityId);
            if (arg2.miniPlayer.level >= 65) 
            {
                this._runeFight.visible = true;
                this._runeFight.updateRuneFight(arg2.runeFight.toString());
            }
            else 
            {
                this._runeFight.visible = false;
            }
            return;
        }

        /* internal  */addUserModel(arg1: Map<any, any> /* flash.utils.Dictionary */, arg2: SPublicMiniPlayer, arg3: int, arg4: int): void
        {
            if (this._userModel != null) 
            {
                this._userModel.dispose(false);
            }
            else 
            {
                this._userModel = new StatueUserPlayer();
            }
            this._userModel.direction = DirectionType.South;
            this._userModel.camp = arg2.camp;
            this._userModel.sex = arg2.sex;
            this._userModel.career = arg2.career;
            this._userModel.reserveJs.weaponStPerLv = arg3;
            this._userModel.reserveJs.wingStrPerLv = arg4;
            this._userModel.updateEquipByDic(arg1);
            this._userModel.x = 127;
            this._userModel.y = 280;
            addChildAt(this._userModel, 3);
            return;
        }

        public setNotOnline(arg1: Boolean=true): void
        {
            if (this._userModel) 
            {
                this._userModel.dispose(false);
            }
            var loc1=[];
            var loc2=Cache.instance.pack.rolePackCache.sbag.capacity;
            var loc3=0;
            while (loc3 < loc2) 
            {
                loc1.push(null);
                ++loc3;
            }
            this._equipsPanel.setEquipments(loc1);
            if (arg1) 
            {
                this._notOnline.text = Language.getString(30005);
                this._notOnline.setTextFormat(this._notOnlineTf);
            }
            else 
            {
                this._notOnline.text = "";
            }
            this._adoreNum.text = "0";
            this._adoreNum.setTextFormat(this._adoreTf);
            this._despiseNum.text = "0";
            this._despiseNum.setTextFormat(this._despiseTf);
            this._adoreBtn.enabled = false;
            this._despiseBtn.enabled = false;
            this._campTxt.text = "";
            this._nameTxt.text = "";
            this._levelTxt.text = "";
            this._careerTxt.text = "";
            this._level.text = "";
            this._career.text = "";
            this._fightStrengthTxt.text = "--";
            this._strengthAddPanel.visible = false;
            this._jewelAddPanel.visible = false;
            this._vipItem.vip = 0;
            this._avatarUpload.visible = false;
            this._avatarUpload.reset();
            this._runeFight.visible = false;
            return;
        }

        public showVote(): void
        {
            this._restVoteTxt.text = Language.getStringByParam(32062, Math.abs(Cache.instance.ranking.voteCount));
            this._restVoteTxt.setTextFormat(GlobalStyle.textFormat5);
            return;
        }

        public setPlayerInfo(arg1: TToplist): void
        {
            if (arg1 == null) 
            {
                return;
            }
            var loc1=ColorConfig.instance.getCountryColor(arg1.propertyOne).intColor;
            var loc2=GameDefConfig.instance.getECamp(arg1.propertyOne);
            this._nameTxt.text = "·" + arg1.entityName;
            this._nameTxt.setTextFormat(this._nameTf);
            this._campTxt.text = loc2;
            this._campTxt.setTextFormat(new GTextFormat("", 13, loc1));
            return;
        }

        public setVoteBtn(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._adoreBtn.visible = true;
                this._despiseBtn.visible = true;
                this._restVoteTxt.visible = true;
            }
            else 
            {
                this._adoreBtn.visible = false;
                this._despiseBtn.visible = false;
                this._restVoteTxt.visible = false;
            }
            return;
        }

        /* internal */ /* const */Vote_Adore_Type: int=1;

        /* internal */ /* const */Vote_Despise_Type: int=2;

        /* internal */ /* var */_career: Object /* flash.text.TextField */;

        /* internal */ /* var */_restVoteTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_fightStrengthTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_strengthAddPanel: EquipmentStrengthAddPanel;

        /* internal */ /* var */_notOnline: Object /* flash.text.TextField */;

        /* internal */ /* var */_vipItem: GuildVipItem;

        /* internal */ /* var */_closeBtn: GButton;

        /* internal */ /* var */_avatarUpload: AvatarUploadPanel;

        /* internal */ /* var */_runeFight: PlayerRuneFightBtn;

        /* internal */ /* var */_equipsPanel: EquipsPanel;

        /* internal */ /* var */_jewelAddPanel: EquipmentJewelAddPanel;

        /* internal */ /* var */_adoreTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_despiseTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_stagerect: Object /* flash.geom.Rectangle */;

        /* internal */ /* var */_notOnlineTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_adoreNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_despiseNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_adoreBtn: GButton;

        /* internal */ /* var */_despiseBtn: GButton;

        /* internal */ /* var */_adore: int;

        /* internal */ /* var */_despise: int;

        /* internal */ /* var */_type: int;

        /* internal */ /* var */_playerId: int;

        /* internal */ /* var */_careerTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_campTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_level: Object /* flash.text.TextField */;

        /* internal */ /* var */_userModel: StatueUserPlayer;
    }
